package com.ichir.projects.uiframework.xml.loader;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import com.ichir.projects.uiflow.definition.IFlowDefinition;
import com.ichir.projects.uiframework.xml.XmlFlowDefinition;


/**
 * {@link XmlFlowDefinition} initializer.
 * 
 * @author mahieddine_ichir
 */
public class XmlUiFlowLoader {

	/**
	 * UI Flow reference: initialized via {@link #load(InputStream)}.
	 */
	private XmlFlowDefinition flow;
	
	/**
	 * Load an XML UI Flow.
	 * @return 
	 * @throws Exception
	 */
	public XmlUiFlowLoader load(InputStream is) throws Exception {
		JAXBContext context = JAXBContext.newInstance(XmlFlowDefinition.class);
		Unmarshaller unmarshaller = context.createUnmarshaller();
		flow = (XmlFlowDefinition) unmarshaller.unmarshal(is);
		return this;
	}

	/**
	 * @return the flow
	 */
	public IFlowDefinition getFlowDefinition() {
		return flow;
	}

	/**
	 * @param flow the flow to set
	 */
	public void setFlowDefinition(XmlFlowDefinition flow) {
		this.flow = flow;
	}
}
